﻿// JavaScript Document
function $(objname) { return document.getElementById(objname); }
var request = {
    QueryString: function(val) {
        var uri = window.location.search;
        var re = new RegExp("" + val + "=([^&?]*)", "ig");
        return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
    } 
}
function searchgo() {
    var a = document.getElementById("keyword");
    var b = document.getElementById("search_tab");
    var link;
    if (b.value == 10) {
        link = "http://zixun.58.com/plus/search1.php?search_tab=1&kwtype=0&keyword=" + a.value;
    }
    else {
        //http://bj.58.com/house/?key=fdsaffdsaf
        link = "/" + b.value + "/?key=" + encodeURI(a.value);
    }
    window.location = link;
    return true;
}
//bcity_ad_tou
var notestr = '';

function InitNote() {
    if (notestr == '') return;
    else {
        var startStr = '<div id="show_notice">';
        var endStr = '<div class="ico_close" onclick="$(\'show_notice\').style.display=\'none\'"></div></div>';
        document.write(startStr + notestr + endStr);
    }
}

var infojumptime = 0;
var infojumptext = '本类';
var infojumpurlhref = '/';

function Infojump() {
    //infojumpurlhref = "http://sou.58.com/?key3="+encodeURI(infojumptext);

    if (infojumptime == 10) { top.window.location = infojumpurlhref; }
    else {
        document.getElementById("jumpinfo").innerHTML = "此信息已过期，58推荐您浏览本类最新信息，<strong>" + (10 - infojumptime) + "</strong> 秒跳转到 <a href='" + infojumpurlhref + "' style='text-decoration:underline;'>" + infojumptext + "</a> 类别页";
        infojumptime++;
        window.setTimeout(Infojump, 1000);
    }
}

function searchList() {
    window.location.href = "/sou/?key=" + encodeURI(document.getElementById("keyword").value);
}
function keysearch(evt) {
    var k = window.event ? evt.keyCode : evt.which;
    if (k == 13) { window.location.href = "/sou/?key=" + encodeURI(document.getElementById("keyword").value); }
}

function GetCookies(name) {
    var arr = document.cookie.match(new RegExp(name + "=([^&;]+)"));
    if (arr != null) { return decodeURI(arr[1]); }
    return "";
}

function SetCookie(value) {
    var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = "58home=" + escape(value) + ";domain=58.com;expires=" + exp.toGMTString();
}

function clickGo() {
    var key = encodeURI(document.getElementById('keyword').value);
    window.location = "http://q.58.com/" + key;
}

var D0_ggad_str = "";
var D2_ggad_str = "";
function WriteDetail() {
    if (window.location.href.indexOf("huochepiao") > 0) {
        document.write('<iframe src="http://pic2.58.com/qunar_frame.html" width="100%" height="160" frameborder="0" scrolling="no"></iframe>');
    }
    else {
        if (D2_ggad_str == "") { setTimeout(WriteDetail, 1000); }
        else { $('detailad_div').innerHTML = D2_ggad_str; }
    }
}
function WriteDetailJD() {
    if (window.location.href.indexOf("huochepiao") > 0) {
        document.write('<iframe src="http://pic2.58.com/7days.html" width="100%" height="200" frameborder="0" scrolling="no"></iframe>');
    }
    else {
        if (D2_ggad_str == "") { setTimeout(WriteDetail, 1000); }
        else { $('detailad_div').innerHTML = D2_ggad_str; }
    }
}

function switchnavtab(aa) {

    try {
        if ($("hottab") != null) { var obja = $("hottab").getElementsByTagName("a"); }
        for (i = 0; i < 6; i++) { if (obja[i].className != "moreservice"); obja[i].className = ""; }
        obja[aa].className = "selected";
    }
    catch (err) { return true; }
}
function settopswitchtab(rootid) {
    switch (rootid) {
        case 1: switchnavtab(0); break;
        case 7: switchnavtab(1); break;
        case 3: switchnavtab(2); break;
        case 4: switchnavtab(3); break;
        case 5: switchnavtab(4); break;
        case 6: switchnavtab(5); break;
        default: switchnavtab(2); break;
    }
}

function writeUserName() {
    if (!(document.cookie!=null&&document.cookie != '' && document.cookie != 'undefined')) {
        var exp = new Date(); exp.setTime(exp.getTime() + 30 * 24 * 60 * 60 * 1000);
        document.cookie = "supportcookie=true;domain=58.com;expires=" + exp.toGMTString();
        if (!(document.cookie != null && document.cookie != '' && document.cookie != 'undefined')) {
            document.write('<script type="text/javascript" src="http://user.58.com/UserLoginState.ashx"></script>');
            return true;
        }
    }
    var host = window.location.hostname;
    var hosthome = host.substr(0, host.indexOf("."));
    var outurl = window.location.href;
    var str = '<a href="http://www.58.com/fabu/" target="_self">发布信息</a> <a href="http://my.58.com/login/?path=' + outurl + '" target="_self">登录</a> <a href="http://my.58.com/reg/?city=' + hosthome + '" target="_self">注册</a>';

    var str2 = '<a href="http://www.58.com/fabu/" target="_self">发布信息</a> <a href="http://my.58.com/login/?path=' + outurl + '" target="_self">登录</a> <a href="http://my.58.com/reg/?city=' + hosthome + '" target="_self">注册</a>';

    try {
        if (GetCookies("UserName") != "") {
            var msgcount = parseInt(GetCookies("MsgUnReadTotal")) + parseInt(GetCookies("SystemUnReadTotal")) + parseInt(GetCookies("RequireFriendUnReadTotal")) + parseInt(GetCookies("CommentUnReadTotal"));
            str = '<a href="http://my.58.com/' + GetCookies("UserID") + '/">' + GetCookies("UserName") + '</a> <img alt="站内消息" hspace="4" src="http://pic.58.com/images/icoMail.gif" /><a  href="http://my.58.com/Liuyanjieshou/">(' + msgcount + ')</a> <a href="http://my.58.com/" target="_self">用户中心</a> <a href="http://www.58.com/fabu/" target="_self">发布</a> <a href="http://my.58.com/ajax/loginout/?path=' + outurl + '" target="_self">退出</a>';

            str2 = '<a href="http://my.58.com/' + GetCookies("UserID") + '/">' + GetCookies("UserName") + '</a> <img alt="站内消息" hspace="4" src="http://pic.58.com/images/icoMail.gif" /><a  href="http://my.58.com/Liuyanjieshou/">(' + msgcount + ')</a> <a href="http://my.58.com/" target="_self">用户中心</a> <a href="http://www.58.com/fabu/" target="_self">发布</a> <a href="http://my.58.com/ajax/loginout/?path=' + outurl + '" target="_self">退出</a>';
        }
        if (cityc()) { document.write(str2); }
        else { document.write(str); }

        return true;
    }
    catch (e) { document.write(str); return true; }
}

function writetitle() {
    if (GetCookies("UserName") != "") {
        if ($("TopNow") != null) {
            $("TopNow").innerHTML = '将信息置顶在此效果更好，<a href="http://my.58.com/XinxiGuanli/" style="text-decoration:underline;color:#FF0000;">马上置顶&raquo;</a>';
        }
    }
}

function ieResize() {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var ver = parseFloat(b_version);
    if (browser == "Microsoft Internet Explorer") {
        if (ver < 6.9) { document.body.style.width = (document.documentElement.clientWidth < 1000) ? "1000px" : "auto"; }
        else { document.body.style.minWidth = "1000px"; }
    }
}

function opGo(urlstr) {
    window.location = "http://" + window.location.hostname + urlstr;
}

function recContent(contentid) { var txtcont = "[quote]" + contentid + "[/quote]"; $("txtContent").value = txtcont; }
function SetupRevert() {
    var WRevert = "";
    if (GetCookies("UserName") == "") { WRevert = "匿名"; }
    else { WRevert = "欢迎您:" + GetCookies("UserName") + "&nbsp;&nbsp;&nbsp;&nbsp;<label for=\"chkUser\"><input type=\"checkbox\" name=\"chkUser\" id=\"chkUser\" value=1 />匿名发布</label>"; }
    if ($("ReverUser") != null) {
        $("ReverUser").innerHTML = WRevert + $("ReverUser").innerHTML;
    }
}

function getText(objname) {
    var reg = /<div id="?\w[^>]*"?>\w*[^<]*<\/div>/ig;
    return $(objname).innerHTML.replace(reg, "");
}
function InitDiscus() {
    return true;
}
var changecity = {
    mode: "iframe",
    url: "http://pic2.58.com/changecity.htm",
    ot: "",
    createFrame: function() {
        if (this.ot == "") {
            document.getElementById("all_city").innerHTML = '<iframe id="chf" scrolling="no" width="400" height="210" src="' + this.url + '" frameborder="0"></iframe>';
        }
        else {
            document.getElementById("all_city").innerHTML = '<iframe id="chf" scrolling="no" width="400" height="210" src="' + this.url + "?" + this.ot + '" frameborder="0"></iframe>';
        }
    },
    changeClass: function(className) {
        if (className == "sc") {
            if (!document.getElementById("chf")) {
                this.url = "http://www.58.com/ichangecity.aspx";
                this.createFrame();
            }
        }
        document.getElementById('all_city').className = className;
    }
}
function getUserMsg() {
    return true;
    var d = new Date();
    if (d.getHours() < 21 && d.getHours() > 14) {
        document.write('<div style=" border-bottom:1px solid #f80; background:#FFFFCC; padding:5px; color:#F00; text-align:center">亲爱的58用户，我们将在今晚(2009-3-10)的19：00-21：00进行系统维护，届时可能会出现异常情况，维护完毕后将恢复正常，给大家带来的不便请谅解！</div>');
    }
}
/* old ad*/
var picnum = 0; var pageadstr = ""; var adtongstr = "";
function setimggo() { var stra = pageadstr.split('|'); $('top_ad_pic').innerHTML = stra[picnum]; picnum++; $('numtext').innerHTML = picnum + "/" + (stra.length - 1); if (picnum == (stra.length - 1)) picnum = 0; }
function goPlay() { var stra = pageadstr.split('|'); if (pageadstr == "") $('top_ad_pic').innerHTML = "<a href='http://biz.58.com' target='_blank'><img src='http://pic2.58.com/images/newcopy/default_newcopy_zs.gif'></a>"; else { $('top_ad_pic').innerHTML = stra[0]; $('numtext').innerHTML = parseInt(picnum + 1) + "/" + (stra.length - 1); var a = setInterval(setimggo, 3000); } }
//bcity_ad_tou
function goPlayTong() {
    if (adtongstr == "") return;
    var stra = adtongstr.split('|');
    //if(adtongstr=="")	 $('tong_ad').innerHTML = "";	
    if (stra.length == 2) $('tong_ad').innerHTML = stra[0];
    else if (stra.length > 2) { $('tong_ad').innerHTML = stra[0]; picnum++; var a = setInterval(setimggo2, 3000); }
}
function setimggo2() { var stra = adtongstr.split('|'); $('tong_ad').innerHTML = stra[picnum]; picnum++; if (picnum == (stra.length - 1)) picnum = 0; }
// mini_price_search
function SubmitSearch() {
    document.getElementById('cflid1').className = 'cfldiv';
    try {
        var i = 0, n = 0, key = "", value = "";
        var listUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
        var query = decodeURIComponent(window.location.search.toString().substring(1));
        var lprice = parseInt(document.getElementById("lprice").value);
        var rprice = parseInt(document.getElementById("rprice").value);

        var query_t = "";
        var sel = document.getElementById("st");
        var sel_v = sel.options[sel.selectedIndex].value;
        if (sel_v != 0) {
            var now = new Date();
            var year = now.getFullYear(), month = now.getMonth(), day = now.getDate();
            var maxd = year + "-" + (month + 1) + "-" + (day + 1);
            var min_d = new Date(year, month, day + 1 - parseInt(sel_v));
            year = min_d.getFullYear(), month = min_d.getMonth(), day = min_d.getDate();
            query_t = "postdate=" + year + "-" + (month + 1) + "-" + day + "_" + maxd;
        }
        if (lprice > 0 && rprice > 0) {
            if (lprice > rprice)
                query = "minprice=" + rprice + "_" + lprice;
            else
                query = "minprice=" + lprice + "_" + rprice;
        }
        else {
            if (lprice > 0)
                query = "minprice=0_" + lprice;
            else if (rprice > 0)
                query = "minprice=0_" + rprice;
            else
                query = "";
        }
        var url = window.top.location.href.replace(window.location.search, "").toString();
        var reg = /\/pn[\d]+/ig;
        url = url.replace(reg, "");
        if (url.substring(url.length - 1) == "/")
            url = url.substring(0, url.length - 1);
        var append = "";
        if (query == "") {
            if (query_t != "")
                append = url + "/?" + encodeURI(query_t);
        }
        else {
            if (query_t == "")
                append = url + "/?" + encodeURI(query);
            else
                append = url + "/?" + encodeURI(query + "&" + query_t);
        }
        if (append.substring(append.length - 1) == "?")
            append = append.substring(0, append.length - 1);
        window.top.location = encodeURI(append);
    }
    catch (err) {
        return true;
    }
}
// mini_price_search
function showdiv() {
    if ($("downlist") != null) $('downlist').className = 'sc';
    if ($("pubdatesel") != null) $('pubdatesel').className = 'hc';
    if ($("downlist") != null) $('downlist').focus();
}
function setPriceSel() {
    var query = decodeURIComponent(window.location.search.toString().substring(1));
    var tj = query.split("&");
    var i = 0; n = tj.length;
    for (i = 0; i < n; i++) {
        if (tj[i].toString().indexOf("minprice") > -1) {
            var price = tj[i].split("=")[1].split("_");
            document.getElementById("lprice").value = price[0];
            document.getElementById("rprice").value = price[1];
        }
        else if (tj[i].toString().indexOf("postdate") > -1) {
            var diff = new Date().getDate() + 1 - (tj[i].toString().split("=")[1].split("_")[0].split("-")[2]);
            var sel = document.getElementById("st");
            for (var i = 0; i < sel.options.length; i++) {
                if (sel.options[i].value == diff) {
                    sel.options[i].selected = true;
                    break;
                }
            }
        }
    }
}
function onKey() {
    if (event.keyCode == 13) {
        SubmitSearch();
    }
}


document.onclick = function() {
    if ($("downlist") != null) $("downlist").className = 'hc';
    if ($("pubdatesel") != null) $('pubdatesel').className = 'sc';
    if ($("cflid1") != null) {
        with (window.event.srcElement) {
            if (tagName.toLowerCase() != "input") $("cflid1").className = "hc";
        }
    }
    if ($("cflid2") != null) {
        with (window.event.srcElement) {
            if (tagName.toLowerCase() != "input") $("cflid2").className = "hc";
        }
    }
    if ($("moreclassdiv") != null) {
        with (window.event.srcElement) {
            if (tagName.toLowerCase() != "a") { $("moreclassdiv").className = "hc"; setmoreclass(0) }
        }
    }
    try { win.closeToolTipWindow(); } catch (e) { return true; }
}